﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Payment", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Payment))]
    public class PaymentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IPayment clazz;
        
        public PaymentSerializer(IPayment clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Type");
            if (clazz.Type!=null) {
                Writer.WriteTypeAttribute("http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", ">>Payment>Type");
                Writer.WriteString(clazz.Type.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Type");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("BaseCurrencyAmount");
            if (clazz.BaseCurrencyAmount!=null) {
                Writer.WriteTypeAttribute("http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", ">>Payment>BaseCurrencyAmount");
                Writer.WriteString(clazz.BaseCurrencyAmount.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : BaseCurrencyAmount");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Amount");
            if (clazz.Amount!=null) {
                Writer.WriteTypeAttribute("http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", ">>Payment>Amount");
                Writer.WriteString(clazz.Amount.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Amount");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Currency");
            if (clazz.Currency!=null) {
                Writer.WriteTypeAttribute("http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", ">>Payment>Currency");
                Writer.WriteString(clazz.Currency.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Currency");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "Type")) {
                goto Type;
            }
            else {
                if ((Reader.LocalName == "BaseCurrencyAmount")) {
                    goto BaseCurrencyAmount;
                }
                else {
                    if ((Reader.LocalName == "Amount")) {
                        goto Amount;
                    }
                    else {
                        if ((Reader.LocalName == "Currency")) {
                            goto Currency;
                        }
                        else {
                            return;
                        }
                    }
                }
            }
        Type:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payment>Type");
            }
            clazz.Type = new Payment.TypeType(Reader.ReadElementString("Type"));
            goto START;
        BaseCurrencyAmount:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payment>BaseCurrencyAmount");
            }
            clazz.BaseCurrencyAmount = new Payment.BaseCurrencyAmountType(Reader.ReadElementString("BaseCurrencyAmount"));
            goto START;
        Amount:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payment>Amount");
            }
            clazz.Amount = new Payment.AmountType(Reader.ReadElementString("Amount"));
            goto START;
        Currency:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payment>Currency");
            }
            clazz.Currency = new Payment.CurrencyType(Reader.ReadElementString("Currency"));
            goto START;
        }
    }
}
